package com.controller.story;

import com.domain.HttpResponse;
import com.dto.StoryExtDto;
import com.mapper.generator.ShStoryMapper;
import com.pojo.ShTag;
import com.service.story.StoryService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by Huoyunren on 2016-07-01.
 */
@Controller
@RequestMapping("story")
public class StoryController {
  @Autowired
  private StoryService storyService;
  @Autowired
  private ShStoryMapper storyMapper;

  @RequestMapping("list")
  @ResponseBody
  public Object list(@Param("pageNo") Integer pageNo, @Param("pageSize") Integer pageSize,@Param("email")String email,@Param("orderField")String orderField,@Param("storyType")Integer storyType,@Param("tag")Integer tag) {
    return storyService.list(pageNo, pageSize,email,orderField,storyType,tag);
  }
  @RequestMapping("bulletin")
  @ResponseBody
  public Object bulletin(@Param("pageNo") Integer pageNo, @Param("pageSize") Integer pageSize,@Param("email")String email,@Param("orderField")String orderField,@Param("storyType")Integer storyType) {
    return storyService.bulletin(pageNo, pageSize,email,orderField,storyType);
  }

  @RequestMapping("save")
  @ResponseBody
  public Object save(@Param("title") String title, @Param("subTitle") String subTitle, @Param("content") String content, @Param("email") String email, @Param("img") String img,@Param("storyType")Integer storyType,@Param("chooseTag")Integer chooseTag) {
    return storyService.save(email, title, subTitle, content, img,storyType,chooseTag);
  }

  @RequestMapping("info")
  public ModelAndView info(@Param("uuid") String uuid) {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("/story/info");
    StoryExtDto storyExtDto = storyService.queryByUuid(uuid);
    modelAndView.addObject("story",storyExtDto);
    return modelAndView;
  }

  @RequestMapping("incrReadCount")
  @ResponseBody
  public Object incrReadCount(@Param("uuid") String uuid) {
    storyService.incrReadCount(uuid);
    return HttpResponse.OK();
  }
  @RequestMapping("del")
  @ResponseBody
  public Object del(@Param("bulletinId") Integer bulletinId) {
    storyMapper.deleteByPrimaryKey(bulletinId);
    return HttpResponse.OK();
  }
}
